/* global hexo */

'use strict';

hexo.extend.helper.register('add_descr', (post) => {
  let ans = '';
  const excerptLength = 180;
  let left = 0;
  // console.log(post.excerpt.length);
  if (post.excerpt.length > 0) {
    // console.log(post);
    for (let index = 0; index < post.excerpt.length; index++) {
      const element = post.excerpt[index];
      if (element == '<') {
        left++;
        continue;
      }
      if (element == '>') {
        left--;
        ans = ''.concat(ans, ' ');
        continue;
      }
      if (left == 0) {
        ans = ''.concat(ans, element);
        if (ans.length >= excerptLength) {
          break;
        }
      }
    }
  }
  ans = ''.concat(ans, '......');
  return `<p style="padding-left: 2em; font-size: 0.8125em; color: #999;"> ${ans} </p>`;
});

// 前180个字
// 字号啥的统一
// 最后保底六个点
